import os
import json

_current_path = os.path.dirname(os.path.abspath(__file__))

def write_obj(output_file, obj, index=0):
    for key, value in obj.items():
        if key.startswith('_'):
            continue

        # 将键值对写入文件
        if type(value) is str:
            new_value = value.replace('\\', '\\\\')
            output_file.write(f'{key} = "{new_value}"')
        else:
            output_file.write(f'{key} = {value}')
        output_file.write('\n')

with open(os.path.join(_current_path, '..', 'lib', 'config.py'), 'w') as f:
    _current_path = os.path.dirname(os.path.abspath(__file__))
    # 解析配置信息
    with open(os.path.join(_current_path, '..', '..', 'config.json'), 'r') as file:
        _config = json.load(file)
    
    write_obj(f, _config)
